var that;
var app = getApp();
Page({
  data: {
    disabled: true
  },
  onLoad: function() {
    that = this;
    that.setData({
      disabled: false
    })
  },
  //用户点击允许获取昵称和头像信息之后的调用
  bindGetUserInfo: function(e) {
    console.log(e)
    that.setData({
      disabled: true
    })
    let userInfo = e.detail.userInfo;
    if (!userInfo) {
      wx.showModal({
        title: '提示',
        content: '请选择允许',
      })
      that.setData({
        disabled: false
      })
      return;
    }
    userInfo.avatarUrl = that.headimgHD(userInfo.avatarUrl);
    wx.showLoading({
      title: '正在登录...',
    })
    app.modifUserinfo(userInfo, function(res) {
      wx.hideLoading();
      if (!res) {
        that.setData({
          disabled: false
        })
        return;
      }
      wx.navigateBack();
    });
  },
  headimgHD: function(imageUrl) {
    console.log('原来的头像', imageUrl);
    imageUrl = imageUrl.split('/'); //把头像的路径切成数组

    //把大小数值为 46 || 64 || 96 || 132 的转换为0
    if (imageUrl[imageUrl.length - 1] && (imageUrl[imageUrl.length - 1] == 46 || imageUrl[imageUrl.length - 1] == 64 || imageUrl[imageUrl.length - 1] == 96 || imageUrl[imageUrl.length - 1] == 132)) {
      imageUrl[imageUrl.length - 1] = 0;
    }

    imageUrl = imageUrl.join('/'); //重新拼接为字符串

    console.log('高清的头像', imageUrl);

    return imageUrl;
  },
});